<html lang="en">
<head>
    <title>大家都在看</title>
    <#include "../common/header.ftl">
    <script type="text/javascript" src="/js/plugins/jquery-form/jquery.form.js"></script>
    <script>
        $(function () {
            $(".editRelationBtn").click(function () {
                //将数据设置进去,第一个下拉框的选择
                var strategyId = $("#strategyId").val();
                if(strategyId == -1){
                    $.messager.alert("温馨提示:选择攻略")
                    return;
                }
                var strategyHtml = $('#strategyId option:selected').html();
                $("#editForm input[name='name']").val(strategyHtml);
                $("#editForm input[name='strategyId']").val(strategyId);
                console.log(strategyId);
                //发送ajax查询出游记
                $.get("/travel/getRegionTravelByStrategyId.do",{strategyId:strategyId},function (data) {
                    //将游记设置到中
                    var html= "";
                    $.each(data,function (index, item) {
                        html += "<option value='"+item.id+"'>"+item.title+"</option>";
                    })
                    $("#editForm select[name='travelId']").html(html);
                })
                $("#editModal").modal("show");

            })
        //修改操作
        $(".saveBtn").click(function () {
            //提交表单之前判断是否选中推荐的类型,如果不等于-1,在提交表单,否则不提交表单
            $('#editForm').ajaxSubmit(
                    function (data) {
                        if(data.success){
                            window.location.href="/strategy/lookList.do?strategyId="+${strategyId!};
                        }else {
                            $.messager.alert("温馨提示",e.msg);
                        }
                    }
            )
        })
})

    </script>
</head>
<body>
<!--左侧菜单回显变量设置-->
<#assign currentMenu="lookList">
<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-2">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-10">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">大家都在看</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategy/lookList.do" method="post">
                <div class="form-group">
                    <label for="keyword">攻略搜索:</label>
                    <div class="form-group" >
                        <div class="col-sm-6">
                            <select id="strategyId" name="strategyId"  class="form-control">
                                <option value="-1">--请选择--</option>
                                <#list strategys as s>
                                     <option value="${s.id}">${s.title}</option>
                                </#list>
                            </select>
                            <script>
                               $("#strategyId").val(${strategyId!})
                            </script>
                        </div>
                    </div>
                </div>
                <button id="btn_query" class="btn btn-info"><span class="glyphicon glyphicon-search"></span> 查询</button>
                <a id="btn_query" class="btn btn-info editRelationBtn"><span class="glyphicon glyphicon-search"></span>添加关联</a>
            </form>
            关联游记
            <table class="table table-striped table-hover">
               <#list travels as entity >
                     <tr>
                         <td>${entity.title!}</td>
                         <td>
                             <a href="/travel/releaseList.do?travelId=${entity.id}" class="btn ">查看游记文章</a>
                             <a href="/strategy/deleteRelation.do?travelId=${entity.id}&strategyId=${strategyId}" class="btn">删除</a>
                         </td>
                     </tr>
                </#list>
            </table>
        </div>
    </div>
</div>
<#--攻略分类编辑模态框-->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span> </button>
                <h4 class="modal-title">添加和编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/strategy/saveRelation.do" method="post" id="editForm">
                    <input type="hidden" name="strategyId">
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">所属攻略：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name" value="" readonly>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">关联游记：</label>
                        <div class="col-sm-6">
                            <select name="travelId" class="form-control">
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="submit" class="btn btn-primary saveBtn" >保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal" >取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
